#include "3DEDefine.h"
#include "MCameraIphoneHandler.h"
#include "MCamera.h"

CMCameraIphoneHandler::CMCameraIphoneHandler(void)
{
	
}

CMCameraIphoneHandler::~CMCameraIphoneHandler(void)
{
}


//////////////////////////////////////////////////////////////////////////
int  CMCameraIphoneHandler::_HandleMessages( UINT hWnd, UINT uMsg, UINT wParam, UINT lParam ) 
{
    int x = wParam;
    int y = lParam;

	switch( uMsg )
	{

	case eTouchBegin:
		{  	SetMousePos(x,y);	
		}
		 break;

	case eTouchMove:
		{
			//POINTF ptf = DeltaMousePosition(x,y);
			//ptf.x /= 1200.0f;
			//ptf.y /= 1200.0f;
			//m_pCamera->MovePosition(ptf.x,ptf.y);	
			SetMousePos(x,y);
		} 
		break;

	case eTouchEnd:
		{ SetMousePos(x,y);
		}
		 break;

	case eTouchRotate:
		{

			/*
			POINTF ptf = DeltaMouseRotation(x,y);

			if(fabs(ptf.x) >= fabs(ptf.y))
			{  m_pCamera->MakeRotateByYAxis(ptf.x);
			}
			else
			{  m_pCamera->MakeRotateByXAxis(ptf.y);
			}
			*/

			SetMousePos(x,y);
		}
		break;	

	case eButtonLeft:
    case eButtonRight:	
		{
			/*
			POINTF ptf = DeltaMouseRotation(x,y);
            m_pCamera->MakeRotateByYAxis(ptf.x);
			/**/
		}
		break;


	case eButtonTop:
    case eButtonBottom:
		{
			/*
			POINTF ptf = DeltaMouseRotation(x,y);
			m_pCamera->MakeRotateByXAxis(ptf.y);
			/**/
		}
		 break;

	
		 

	case eButtonReset:
		{
			/*
			vec3 vEye    = vec3(15.0f,15.0f,15.0f);
			vec3 vlookat = vec3(0,0,0);
			m_pCamera->SetViewParams(vEye,vlookat);
			/**/
		}
		 break;

	case eMTouchMove:
		{
			/*
			int _x = (short)LOWORD(lParam);
			int _y = (short)HIWORD(lParam);

			int nSign = wParam;
			
			nSign = (nSign == 1) ? 1 : - 1;  
			
			int zDelta = nSign;
			
			float fDistance = m_pCamera->GetDistance();

			if(zDelta < 0)
			{
				m_pCamera->SetDistance(fDistance - 10.0f);
			}
			else if(zDelta > 0)
			{
				m_pCamera->SetDistance(fDistance + 10.0f);
			}
			
			SetMousePos(_x,_y);
			/**/
		}
	    break; 
	}

	return 0;
}